package com.soft.servlet;

import com.soft.dao.UserLogin;
import com.soft.pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //从前端拿到账号密码
        String username = request.getParameter("username");
        String password = request.getParameter("password");

        //查询数据库
        User user  = UserLogin.login(username,password);

        if (user == null) {
            System.out.println("登陆失败");
            request.getRequestDispatcher("error").forward(request,response);
        } else {
            System.out.println("登录成功");
            request.getRequestDispatcher("success").forward(request,response);
        }


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
